//
// Created by hay boy on 2022/6/27.
//

#ifndef ALGORITHMS_DERIVEDLINKEDSTACK_H
#define ALGORITHMS_DERIVEDLINKEDSTACK_H
#include "../Stack.h"
#include "../../chainNode/ChainNode.h"

template<class T>
class DerivedLinkedStack : private Chain<T>, public Stack<T> {
public:
    explicit DerivedLinkedStack(int initialCapacity=10):Chain<T>(initialCapacity){}
    bool empty()const{
        return Chain<T>::empty();
    }
    int size() const{
        return Chain<T>::size();
    }
    T& top(){
        try{
            return Chain<T>::get(0);
        }catch(illegalIndex&){
            throw StackEmpty();
        }
    }
    void pop(){
        if(Chain<T>::empty()){
            throw StackEmpty();
        }
        Chain<T>::erase(0);
    }
    void push(const T& theElement){
        Chain<T>::insert(0,theElement);
    }
    void clear(){
        Chain<T>::clear();
    }
};

#endif //ALGORITHMS_DERIVEDLINKEDSTACK_H
